package cn.edu.njust.alg.leetcode;

public class Leetcode_168 {

	public static int titleToNumber(String s) {
		int num = 0;
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			num = 26 * num + (c - 'A' + 1);
		}
		return num;
	}

	public static String convertToTitle(int n) {
		int k = n;
		StringBuffer sb = new StringBuffer();
		while (k != 0) {
			k--;
			int i = k % 26;
			sb.insert(0, (char) ('A' + i ));
			k = k / 26;
		}

		return sb.toString();
	}

	public static void main(String[] args) {

		System.out.println(convertToTitle(26));
	}

}
